################################################################################
#  ETFRoot project, Anyang Normal University && IMP-CAS
#  \brief cmake macros specifically used in ETFRoot
#  \author SUN Yazhou, asia.rabbit@163.com
#  \since 2021-10-06
#  \date 2021-10-06
#  \attention
#  changelog
#  <table>
#  <tr>  <th>Date         <th>Author      <th>Description                  </tr>
#  <tr>  <td>2021-10-06   <td>Asia Sun    <td>file created                 </tr>
#  </table>
#  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
################################################################################

# assign the source files and configure the include and lib directories for
# building libraries in ETFRoot
macro(config_lib)
  aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} sources)
  list(APPEND INCLUDE_DIRECTORIES ${BASE_INCLUDE_DIRECTORIES} ${SYSTEM_INCLUDE_DIRECTORIES}
    ${CMAKE_CURRENT_SOURCE_DIR} ${Geant4VMC_INCLUDE_DIRS} ${Geant4_INCLUDE_DIRS}
  )
  # add all the directories in ${subdirs} to ${INCLUDE_DIRECTORIES}
  # and add all the source files (*.cxx) to ${sources}
  # note that all the generated paths are absolute
  list(REMOVE_DUPLICATES subdirs) # remove duplicates
  foreach(dir ${subdirs})
    # set(dir ${CMAKE_CURRENT_SOURCE_DIR}/${dir})
    list(APPEND INCLUDE_DIRECTORIES ${dir})
    aux_source_directory(${dir} sources)
  endforeach()
  fair_change_extensions_if_exists(.cxx .h FILES "${sources}" OUTVAR headers)
  add_library(${target} SHARED ${sources} ${headers})
  add_library(ETF::${target} ALIAS ${target})
  set_target_properties(${target} PROPERTIES ${PROJECT_LIBRARY_PROPERTIES})
  target_include_directories(${target} PUBLIC ${INCLUDE_DIRECTORIES})
  target_link_directories(${target} PUBLIC ${FAIRROOT_LIBRARY_DIR})
  target_link_libraries(${target} PUBLIC ${dependencies} ${ROOT_LIBRARIES})
  fairroot_target_root_dictionary(${target} HEADERS ${headers} LINKDEF ${linkfiles})
endmacro()
